{block name="style"}
<style>
    form {
        width: calc(100% - 5px);
        height: calc(100% - 15px);
        margin-top: 15px;
    }
</style>
{/block}

{block name="content"}
<form action="{:sysuri()}" method="post" data-auto="true" class="layui-form" lay-filter="shop_add">
    <div class="layui-row layui-col-space10" style="padding: 0 15px;">
        <div class="layui-col-md12">
            <label class="layui-form-label">{:lang("店铺名称")}:</label>
            <div class="layui-input-block">
                <input required name="name" value="{$vo.name|default=''}" class="layui-input">
            </div>
        </div>
        {if !empty($account_show) }
        <div class="layui-col-md12">
            <label class="layui-form-label">{:lang("公司")}:</label>
            <div class="layui-input-block">
                <select name="account_id" class="layui-select" required>
                    <option value="">请选择</option>
                    {if !empty($account_arr) }
                    {foreach $account_arr as $account_id => $account_name }
                    <option value="{$account_id|default=''}" {if ($shop_account == $account_id) } selected  {/if}>{$account_name|default=''}</option>
                    {/foreach}
                    {/if}
                </select>
            </div>
        </div>
        {/if}
        <div class="layui-col-md12">
            <label class="layui-form-label">ClientID:</label>
            <div class="layui-input-block">
                <input required name="client_id" value="{$vo.client_id|default=''}" class="layui-input">
            </div>
        </div>
        <div class="layui-col-md12">
            <label class="layui-form-label">ApiKey:</label>
            <div class="layui-input-block">
                <input required name="api_key" value="{$vo.api_key|default=''}" class="layui-input">
            </div>
        </div>
        <div class="layui-col-md12">
            <label class="layui-form-label">{:lang("币种")}:</label>
            <div class="layui-input-block">
                <select name="currency_id" class="layui-select" required>
                    <option value="">{:lang("请选择")}</option>
                </select>
            </div>
        </div>
    </div>
    <div class="layui-form-item text-center" style="margin-top: 30px;clear: both;">
        <input type="hidden" name="platform_id" value="{$platform_id|default=0}">
        <input type="hidden" name="id" value="{$vo.id|default=0}">
        {if empty($account_show) }
        <input type="hidden" name="account_id" value="{$shop_account|default=0}">
        {/if}
        <button class="layui-btn">{:lang('保存数据')}</button>
        <button class="layui-btn layui-btn-danger" type='button' id="close_btn" data-confirm="{:lang('确定要取消编辑吗')}" data-close>{:lang('取消编辑')}</button>
    </div>
</form>
{/block}

{block name="script"}
<script>
    $(function() {
        let form = layui.form;

        getCurrenList();

        function getCurrenList() {
            $.ajax({
                url: "{:sysuri('common/ajax/getCurrencyList')}",
                type: 'get',
                dataType: 'json',
                success: function(res) {
                    if (res.code == 1) {
                        let data = res.data;
                        let html = '<option value="">{:lang("请选择")}</option>';
                        let currency_id = "{$vo.currency_id|default=''}";
                        for (let i = 0; i < data.length; i++) {
                            if(currency_id){
                                html += '<option value="' + data[i].id + '"'+ (data[i].id == currency_id ? 'selected' : '') + '>' + data[i].currency_name + '</option>';
                            }else{
                                html += '<option value="' + data[i].id + '">' + data[i].currency_name + '</option>';
                            }
                        }

                        $('select[name="currency_id"]').html(html);
                        form.render('select');
                    }else{
                        $.msg.error(res.info)
                        return false;
                    }
                },
                error: function(err){
                    $.msg.error(err.status + err.statusText);
                }
            })
        }
    })
</script>
{/block}